<template>
  <div class="register-container">
    <a-card class="register-card">
      <h2>实践项目教学支持系统</h2>
      <a-form :model="form" @finish="handleSubmit">
        <a-form-item>
          <a-input v-model:value="form.username" placeholder="学号/工号">
            <template #prefix>
              <user-outlined />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-input v-model:value="form.name" placeholder="姓名">
            <template #prefix>
              <smile-outlined />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-radio-group v-model:value="form.role" class="role-select">
            <a-radio-button value="student">学生</a-radio-button>
            <a-radio-button value="teacher">教师</a-radio-button>
          </a-radio-group>
        </a-form-item>

        <!-- 学生特有字段 -->
        <template v-if="form.role === 'student'">
          <a-form-item label="专业" name="major">
            <a-select v-model:value="form.major" placeholder="请选择专业">
              <a-select-option value="software">软件工程</a-select-option>
              <a-select-option value="computer">计算机科学与技术</a-select-option>
              <a-select-option value="network">网络工程</a-select-option>
              <a-select-option value="iot">物联网工程</a-select-option>
            </a-select>
          </a-form-item>

          <a-form-item label="班级" name="class">
            <a-select 
              v-model:value="form.class" 
              placeholder="请选择班级"
              :disabled="!form.major"
            >
              <template v-if="form.major === 'software'">
                <a-select-option value="software-2023-1">2023级软件工程1班</a-select-option>
                <a-select-option value="software-2023-2">2023级软件工程2班</a-select-option>
              </template>
              <template v-if="form.major === 'computer'">
                <a-select-option value="computer-2023-1">2023级计算机科学1班</a-select-option>
                <a-select-option value="computer-2023-2">2023级计算机科学2班</a-select-option>
              </template>
              <template v-if="form.major === 'network'">
                <a-select-option value="network-2023-1">2023级网络工程1班</a-select-option>
                <a-select-option value="network-2023-2">2023级网络工程2班</a-select-option>
              </template>
              <template v-if="form.major === 'iot'">
                <a-select-option value="iot-2023-1">2023级物联网工程1班</a-select-option>
                <a-select-option value="iot-2023-2">2023级物联网工程2班</a-select-option>
              </template>
            </a-select>
          </a-form-item>
        </template>

        <a-form-item>
          <a-input-password v-model:value="form.password" placeholder="密码">
            <template #prefix>
              <lock-outlined />
            </template>
          </a-input-password>
        </a-form-item>
        <a-form-item>
          <a-input-password v-model:value="form.confirmPassword" placeholder="确认密码">
            <template #prefix>
              <lock-outlined />
            </template>
          </a-input-password>
        </a-form-item>
        <a-form-item>
          <a-input v-model:value="form.email" placeholder="邮箱">
            <template #prefix>
              <mail-outlined />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-input v-model:value="form.phone" placeholder="手机号">
            <template #prefix>
              <phone-outlined />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-button type="primary" html-type="submit" block :loading="loading">注册</a-button>
        </a-form-item>
        <div class="login-link">
          已有账号？<a @click="$router.push('/')">立即登录</a>
        </div>
      </a-form>
      <div class="register-footer">
        <div class="footer-links">
          <a @click="$router.push('/help')">帮助</a>
          <a @click="$router.push('/privacy')">隐私条款</a>
        </div>
        <div class="copyright">
          Copyright© 2025 西安欧亚学院
        </div>
      </div>
    </a-card>
  </div>
</template>

<script>
import { 
  UserOutlined, 
  LockOutlined, 
  MailOutlined, 
  PhoneOutlined,
  SmileOutlined 
} from '@ant-design/icons-vue'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'

export default {
  name: 'Register',
  components: {
    UserOutlined,
    LockOutlined,
    MailOutlined,
    PhoneOutlined,
    SmileOutlined
  },
  setup() {
    const router = useRouter()
    const loading = ref(false)
    const form = reactive({
      username: '',
      name: '',
      role: 'student',
      password: '',
      confirmPassword: '',
      email: '',
      phone: '',
      major: '',
      class: ''
    })

    const handleSubmit = () => {
      if (!form.username || !form.password || !form.confirmPassword || !form.name || !form.role) {
        message.error('请填写必填项')
        return
      }

      if (form.role === 'student' && (!form.major || !form.class)) {
        message.error('请选择专业和班级')
        return
      }

      if (form.password !== form.confirmPassword) {
        message.error('两次输入的密码不一致')
        return
      }

      loading.value = true
      
      // 模拟注册成功
      setTimeout(() => {
        console.log('注册信息:', form)
        message.success('注册成功')
        router.push('/')
        loading.value = false
      }, 1000)
    }

    return {
      form,
      loading,
      handleSubmit
    }
  }
}
</script>

<style scoped>
.register-container {
  height: 100vh;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: url('../assets/login-bg.jpg') no-repeat center center;
  background-size: cover;
  padding-right: 120px;
}

.register-card {
  width: 360px;
  text-align: center;
  background: rgba(255, 255, 255, 0.9) !important;
  backdrop-filter: blur(10px);
  border: none !important;
}

h2 {
  margin-bottom: 24px;
  color: rgba(0, 0, 0, 0.85);
}

.role-select {
  width: 100%;
  display: flex;
}

.role-select :deep(.ant-radio-button-wrapper) {
  flex: 1;
  text-align: center;
}

.login-link {
  margin-top: 16px;
  text-align: center;
}

.register-footer {
  margin-top: 48px;
  text-align: center;
}

.footer-links {
  margin-bottom: 8px;
}

.footer-links a {
  margin: 0 8px;
  color: rgba(0, 0, 0, 0.45);
}

.copyright {
  color: rgba(0, 0, 0, 0.45);
  font-size: 14px;
}
</style>
